package com.example.musicwebcon.controller;


import com.example.musicwebcon.model.ResponseMessage;
import com.example.musicwebcon.model.dto.localDTO;
import com.example.musicwebcon.model.favorSong;
import com.example.musicwebcon.model.localSong;
import com.example.musicwebcon.service.serviceInterface.IlocalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/local")
public class localController {
    @Autowired
    IlocalService localService;
    //增加
    @PostMapping
    public ResponseMessage add(@Validated @RequestBody localDTO localSong){
        localSong song = localService.add(localSong);
        return ResponseMessage.success(song);
    }
    //查询
    @GetMapping("/{musicId}")
    public ResponseMessage get(@PathVariable String musicId){
        localSong song = localService.getMusicId(musicId);
        return ResponseMessage.success(song);
    }

    //查询所有
    @GetMapping
    public ResponseMessage getAll(){
        Iterable<localSong> songs = localService.getALl();
        return ResponseMessage.success(songs);
    }
    //修改
    @PutMapping
    public ResponseMessage edit(@Validated @RequestBody localDTO localSong){
        localSong song = localService.edit(localSong);
        return ResponseMessage.success(song);
    }

    //删除歌曲
    @DeleteMapping("/{musicId}")
    public ResponseMessage delete(@PathVariable String musicId){
        localService.deleteMusicId(musicId);
        return ResponseMessage.success(null);
    }

}
